package chunmap.app.tools;

import java.util.ArrayList;
import java.util.List;

import chunmap.data.feature.Feature;
import chunmap.data.feature.Shape;
import chunmap.data.feature.VisitAction;
import chunmap.model.elem.Envelope;
import chunmap.model.geom.Geometry;

public class SelectIterator  implements VisitAction {
//	private static final Logger Log = new Logger(Logger.Debug,SelectIterator.class.getName());
	Envelope env;
	public List<Feature> features;

	public SelectIterator(Envelope env) {
		this.env = env;
		features = new ArrayList<Feature>();
		//geometrys.add(env.toPolygon());
	}

	@Override
	public void execute(Feature obj) {
		if (obj instanceof Shape) {
			Shape feature = (Shape) obj;
			Geometry g = feature.getGeometry();
//			if(Log.isDubug()){
//				Log.log(Logger.Debug, "geometry =" +g.getEnvelop()+"envelope="+env.toString());
//			}
			if (g == null)
				return;
			if (env.hasIntersect(g)) {
				features.add(obj);
//				if(Log.isDubug()){
//					Log.log(Logger.Debug, "add feature");
//				}
			}
		}
	}
}
